package com.azzcs.springbootkafka.listener;

import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.kafka.support.Acknowledgment;
import org.springframework.stereotype.Component;

/**
 * @Author: wzg
 * @Date: 2021/4/15 上午10:43
 */
@Slf4j
@Component
public class KafkaConsumer {

    @KafkaListener(topics = "spring-boot-topic",
            groupId = "group-id-spring-boot-kafaka",
            properties = {"auto.offset.reset=earliest"})
    public void consumer(ConsumerRecord<Integer,String> record, Acknowledgment ack){
        log.info("consumer=====>"+record.toString());
//        ack.nack(1000);
        ack.acknowledge();
    }


    @KafkaListener(topics = "track",
            groupId = "group-id-spring-boot-kafaka",
            properties = {"auto.offset.reset=earliest"})
    public void consumer2(ConsumerRecord<Integer,String> record, Acknowledgment ack){
        log.info("consumer=====>"+record.toString());
//        ack.nack(1000);
        ack.acknowledge();
    }
}
